package com.example.Filter;

import com.example.controller.LoginServlet;
import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
@WebFilter(urlPatterns = {"/upload.jsp","/changePass.jsp","/person.jsp","/message.jsp","/rank.jsp"})
public class MyFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        if (req.getSession().getAttribute("user") == null){
            servletRequest.getRequestDispatcher("uploadcheck.jsp").forward(servletRequest, servletResponse);
//            System.out.println(req.getSession().getAttribute("user"));
        }else{
            filterChain.doFilter(servletRequest, servletResponse);
//            System.out.println(req.getSession().getAttribute("user"));
        }
    }
}
